﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Portal.Common.Entity;
using Portal.Logic;
using Portal.Common.Interface;
using Common.Service;
using OC.Common.Entity;
using Common.BasePages;

namespace Portal
{
    public partial class MesageEdit : BasePage
    {
        private UserEntity _User;
        public UserEntity User 
        {
            get 
            {
                if (_User == null) 
                {
                    _User = UserInfo as UserEntity;
                }
                return _User;
            }
        }
        private IPersonSetting _IPersonSetting;
        public IPersonSetting IPersonSetting 
        {
            get 
            {
                if (_IPersonSetting == null) 
                {
                    _IPersonSetting = ServiceContainer.GetService<IPersonSetting>();
                }
                return _IPersonSetting;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack) 
            {
                BindData();
            }
        }

        public void BindData()
        {
            if (!string.IsNullOrEmpty(Request["ID"]))
            {
                string id = Request["ID"];
                List<PersonSettingEntity> list = new PersonSettingLogic().GetById(id);
                PersonSettingEntity entity = list[0];
                txtMsg.Value = entity.SETTING_VALUE;
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request["ID"]))
            {
                string id = Request["ID"];
                int count = new PersonSettingLogic().UpdateMsgById(id, txtMsg.Value);
                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "callback", "<script>this.close();</script>");
            }
            else 
            {
                
                PersonSettingEntity entity = new PersonSettingEntity();
                entity.CREATE_BY = User.USER_CODE;
                entity.CREATE_DATE = DateTime.Now;
                entity.DELEGATOR_STATUS = "0";
                entity.EFFECT_FROM = DateTime.Now;
                entity.IS_ACTIVE = "1";
                entity.SETTING_ITEMS = "常用意见及附言";
                entity.SETTING_VALUE = txtMsg.Value;
                entity.SETTING_TYPE = "2";
                entity.SETTING_SORT = 1;
                entity.UPDATE_BY = User.USER_CODE;
                entity.UPDATE_DATE = DateTime.Now;
                entity.USER_ID = User.USER_ID;
                IPersonSetting.InserData(entity);
                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "callback", "<script>window.close();</script>");
            }
        }
    }
}